/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author brunogh
 */
class Post {

    String url
    String queryString = ""
    String text
    def username = ""
    def password = ""

    String getText() {
        def response
        def conn = new URL(toString()).openConnection()

        conn.requestMethod = "POST"
        conn.doOutput = true

        if(username && password) {
            conn.setRequestProperty("Authorization", "Basic ${username}:${password}")
        }

        if(conn.responseCode == conn.HTTP_OK) {
            response = conn.content.text
        } else {
            response = "URL: "+this.toString()+"\n"+ "RESPONSE_CODE: "+conn.responseCode
        }

        conn.disconnect()
        return response
    }

    String toString() {
        return url+"?"+queryString
    }
	
}

